<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <async-item></async-item>
    </div>
</body>
<script src="js/vue.js"></script>
<script>
    const app = Vue.createApp({
        data() {
            return {
               msg: '异步组件'
            }
        }
    });

    // 异步组件可以通过 defineAsyncComponent 方式来订阅渲染
    app.component('async-item', Vue.defineAsyncComponent( () => {
        return new Promise( (resolve, reject) => {
            setTimeout(()=> {
                resolve( {
                    template: `<div style="width:200px; height:200px; background-color:blanchedalmond;">
                        从服务端返回的异步组件
                        </div>`
                }); 
            }, 2000);
        });
    }));

    app.mount("#app");
</script>
</html>
